package com.siki.www.clock.controller;

import com.siki.salessystemcommon.utils.SystemMsgJsonResponse;
import com.siki.www.clock.dto.PageLogDTO;
import com.siki.www.clock.service.ClockLogService;
import com.siki.www.clock.vo.ClockLogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Keyvonchen in 2021/6/22
 */
@RestController
@Api(tags = "打卡操作相关接口")
@RequestMapping("/api/vi/siki/log")
@CrossOrigin
public class ClockLogController {

    private final ClockLogService clockLogService;

    public ClockLogController(ClockLogService clockLogService) {
        this.clockLogService = clockLogService;
    }

    @PostMapping("/get")
    @ApiOperation(value = "查询单条打卡记录", response = ClockLogVO.class)
    public SystemMsgJsonResponse get(@RequestParam("id") Long id) {
        return SystemMsgJsonResponse.success(clockLogService.get(id));
    }

    @PostMapping("/page")
    @ApiOperation(value = "条件查询打卡日志", response = ClockLogVO.class)
    public SystemMsgJsonResponse getPage(@Validated @RequestBody PageLogDTO dto) {
        return SystemMsgJsonResponse.success(clockLogService.getPageLog(dto));
    }

    @GetMapping("/count")
    @ApiOperation(value = "统计信息", response = ClockLogVO.class)
    public SystemMsgJsonResponse getCount(@RequestParam("date") String date) {
        return SystemMsgJsonResponse.success(clockLogService.count(date));
    }

    @GetMapping("/count/twenty")
    @ApiOperation(value = "近20天的统计信息", response = ClockLogVO.class)
    public SystemMsgJsonResponse getCount() {
        return SystemMsgJsonResponse.success(clockLogService.count());
    }
}
